<template>
  <view class="query-box">
    <tm-sheet style="border-radius: 2px">
      <tm-text :font-size="24" _class="text-weight-b" label="请输入分享链接"></tm-text>
      <tm-divider></tm-divider>

      <tm-input :searchWidth="120" @search="search" prefix="tmicon-search"
                searchLabel="解析" v-model="content"></tm-input>
      <tm-button :round="2" label="粘贴并解析" :font-size="24" :width="650" :height="60" @click="fastSearch"
                 ></tm-button>
    </tm-sheet>


    <tm-sheet style="border-radius: 2px">
      <tm-image preview :width="650" :height="850" :src="coverList[0]"></tm-image>
      <tm-divider></tm-divider>
      <tm-text :font-size="24" _class="text-weight-b" :label="desc"></tm-text>
<!--      <tm-button :round="2" label="下载" :font-size="24" :width="650" :height="60" @click="download"-->
<!--                 :disabled="disabled"></tm-button>-->
      <tm-button :round="2" label="复制到浏览器打开" :font-size="24" :width="650" :height="60" @click="copyLink"
                 :disabled="disabled"></tm-button>
      <!--      <video src="http://sm.mlb9.cn/%E4%B8%8B%E8%BD%BD%20(10).mp4"></video>-->
    </tm-sheet>
  </view>
  <view>

  </view>
</template>

<script>
import {videoQuery} from "@/api/roll";

export default {
  data() {
    return {
      disabled: false,
      content: '',
      pinyin: '',
      "title": "不惧祁同伟，警醒李达康，能力与背景兼具！#人民的名义 #赵东来 #李达康",
      "urlList": [
        "https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0200fg10000cm4lf5jc77u7r6p9dv00&ratio=720p&line=0"
      ],
      "coverList": [
        "https://p3-sign.douyinpic.com/tos-cn-i-0813/o02tErCyAgAIOCerAh62tAgAJxgzxfAGMCAgcA~c5_300x400.webp?x-expires=1704787200&x-signature=xZWluH9oCOz7zVz2zge8wl41D%2BQ%3D&from=3213915784_large&s=PackSourceEnum_DOUYIN_REFLOW&se=false&sc=cover&biz_tag=aweme_video&l=20231226164551891222173B8CAF00F6CC",
        "https://p9-sign.douyinpic.com/tos-cn-i-0813/o02tErCyAgAIOCerAh62tAgAJxgzxfAGMCAgcA~c5_300x400.webp?x-expires=1704787200&x-signature=XkqiydDSdOR1YJSbq7v4kR3J4CU%3D&from=3213915784_large&s=PackSourceEnum_DOUYIN_REFLOW&se=false&sc=cover&biz_tag=aweme_video&l=20231226164551891222173B8CAF00F6CC",
        "https://p26-sign.douyinpic.com/tos-cn-i-0813/o02tErCyAgAIOCerAh62tAgAJxgzxfAGMCAgcA~c5_300x400.webp?x-expires=1704787200&x-signature=Tjdhbc4MaKtKRka8JVotJMToS6s%3D&from=3213915784_large&s=PackSourceEnum_DOUYIN_REFLOW&se=false&sc=cover&biz_tag=aweme_video&l=20231226164551891222173B8CAF00F6CC",
        "https://p3-sign.douyinpic.com/tos-cn-i-0813/o02tErCyAgAIOCerAh62tAgAJxgzxfAGMCAgcA~c5_300x400.jpeg?x-expires=1704787200&x-signature=CeVpv7QwOpP76trLiRgMMyfh0nk%3D&from=3213915784_large&s=PackSourceEnum_DOUYIN_REFLOW&se=false&sc=cover&biz_tag=aweme_video&l=20231226164551891222173B8CAF00F6CC"
      ],
      "desc": "不惧祁同伟，警醒李达康，能力与背景兼具！#人民的名义 #赵东来 #李达康"
    }
  },
  methods: {
    search(e) {
      videoQuery({url: e}).then(res => {
        this.coverList = res.data.coverList
        this.urlList = res.data.urlList
        this.desc = res.data.desc
      }).finally(() => {
        this.content = e
      })
    },
    fastSearch() {
      const that = this
      // 从剪贴板获取数据并赋值给content，调用search方法
      uni.getClipboardData({
        success: function (res) {
          // 调用search方法
          that.search(res.data);
        },
        fail: function (res) {
          // 获取剪贴板数据失败
          console.log(res);
        }
      });

    },
    download() {
      // 下载资源,url为urlList[0]
      if (this.urlList[0]) {
        // console.log('下载资源', this.urlList[0])
        uni.request({
          url: this.urlList[0],
          header: {
            refer: 'https://www.douyin.com/'
          }
        })
        // window.open(this.urlList[0], '_blank', 'noopener=yes,noreferrer=yes');

        // var newTab = document.createElement('a');
        // newTab.href = this.urlList[0];
        // newTab.referrerpolicy = 'no-referrer';
        // newTab.target = '_blank';
        // newTab.click();
        // uni.downloadFile({
        //   url: this.urlList[0],
        //   success: res => {
        //     console.log('下载成功', res)
        //   },
        //   fail: res => {
        //     console.log('下载失败', res)
        //   }
        // })
      }
    },
    copyLink() {
      plus.runtime.openURL( this.urlList[0], (err)=>{
       console.log('打开失败',err)
      }, '' );
      // if (this.urlList[0]) {
      //   uni.setClipboardData({
      //     data: this.urlList[0],
      //     success: res => {
      //       uni.showToast({
      //         title: '复制成功',
      //         icon:'success',
      //         duration: 2000
      //       })
      //     }
      //   })
      // }
    }
  }
}
</script>

<style scoped>

</style>
<style lang="scss">
page {
  background-color: #F7F7F7 !important;
}
</style>
